import request  from  '../util/request';
import { routerRedux } from 'dva/router';
let teacher= {
    namespace: 'teacher',
    state:{
       isLogin:false
    },
    effects:{
          *doLogin({payload},{select,put,call}) {
              let res  =  payload.call(request('/singin',{
                      method:'post',
                      data:payload,
              }));
              if(res.data.errcode != 0) {
                   return alert('用户名或密码不正确!');
              }
              //sessionStorage 关了就没了
              //JSON.stringfy解析json对象
              window.sessionStorage.setItem('user',JSON.stringfy(res.data.user));
              // 更改登录状态
              yield put({type:'changeLogin',payload:{ isLogin:true } });
              // 跳转页面
              yield put(routerRedux.push('/home/list'))

          }
    },
    reducers: {

    }
};
export  default  teacher;
